import { combineReducers } from 'redux'

import { ADD_COMMENT, DEL_COMMENT, RECEIVE_COMMENTS } from './action-types';

const initComments = []

function comments(state = initComments, action) {
	switch (action.type) {
		case ADD_COMMENT:
			return [action.data, ...state]
		case DEL_COMMENT:
			return state.filter((comment, index) => index !== action.data)
		case RECEIVE_COMMENTS:
			return action.data
		default:
			return state;
	}
}

export default combineReducers({
	comments
})